import audio from '@ohos.multimedia.audio';

class GetAudioManager {
  audioManager = {} as audio.AudioManager;
  audioVolumeManager = {} as audio.AudioVolumeManager
  audioVolumeGroupManager = {} as audio.AudioVolumeGroupManager
  groupId: number = audio.DEFAULT_VOLUME_GROUP_ID;
  audioRenderer = {} as audio.AudioRenderer
  audioRoutingManager = {} as audio.AudioRoutingManager
  audioStreamInfo: audio.AudioStreamInfo = {
    samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
    channels: audio.AudioChannel.CHANNEL_1,
    sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
    encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
  };
  audioRendererInfo: audio.AudioRendererInfo = {
    usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
    rendererFlags: 0
  };
  audioRendererOptions: audio.AudioRendererOptions = {
    streamInfo: this.audioStreamInfo,
    rendererInfo: this.audioRendererInfo
  };

  async init() {
    this.audioManager = audio.getAudioManager();
    this.audioVolumeManager = this.audioManager.getVolumeManager();
    this.audioRoutingManager = this.audioManager.getRoutingManager();
    this.audioVolumeGroupManager = await this.audioVolumeManager.getVolumeGroupManager(this.groupId)
  }
}

export const audioManager = new GetAudioManager();
